<?php 
@session_start();
	require_once('../../execute/auth.php');	
	require_once('../execute/inc/config.inc');
	include '../../pagination/ps_pagination.php';
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	
	?>
	<!doctype html>
<html>
	

<head>

	<title>TECHEDU Dashboard</title>
	<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
	<link rel="stylesheet" type="text/css" href="../../assets/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="../../assets/css/bootstrap-responsive.css" />
	<link rel="stylesheet" type="text/css" href="../../assets/css/datepicker.css" />
	<link rel="stylesheet" type="text/css" href="../../assets/css/style.css" />
	<link rel="stylesheet" href="../../assets/css/font-awesome.css" type="text/css">
	
	<script type="text/javascript" src="../../assets/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../../assets/js/bootstrap-datepicker.js"></script>
	<script type="text/javascript" src="../../assets/js/main.js"></script>
	<script type="text/javascript" src="../../assets/js/bootstrap.js"></script>
	<script type="text/javascript" src="../../assets/js/bootstrap.file-input.js"></script>
	<script type="text/javascript" src="../../assets/js/chart.js"></script>
	<script type="text/javascript" src="../../assets/js/bootstrap-typeahead.js"></script>
	<script type="text/javascript" src="../../assets/js/bootstrap-modal.js"></script>
	<script type="text/javascript" src="../../assets/js/jquery.validate.js"></script>
<script type="text/javascript">
	$(function(){
		$(".join").live("click",function(){
			var course_id = $(this).attr("id");
			var student_id = $(this).attr("name");
			window.location.replace("execute/join_course.php?cid="+course_id+"&sid="+student_id);
		});
	});
</script>
<script type="text/javascript">
	$(function(){
		$(".change-password").live("click",function(){
			$("#change-pass-modal").modal();
		});
	});
</script>

<script type="text/javascript">
	$(function(){
		var $validator = $("#updateForm").validate({
		rules: {
			phone: {
			      number: true,
			      minlength: 9,
			      maxlength: 9,
			},
			bio: {
			      minlength: 20,
			      maxlength: 300,
			},
			address: {
			      minlength: 20,
			      maxlength: 300,
			}
		}
	});
	});
</script>

</head>
<body>

	<div class="navbar navbar-fixed-top m-header">
		<div class="navbar-inner m-inner">
			<div class="container-fluid">
				<a class="brand m-brand" style="margin-left:10px;"><small>TECHNATION</small></a>
				
	 <form class="form-search m-search span5">
					<input type="text" placeholder="Type to search" class="span5 search-query">
				</form>
				<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
		 <span class="icon-bar"></span>
		 <span class="icon-bar"></span>
		 <span class="icon-bar"></span>
		 </button>
		 
				<div class="nav-collapse collapse">
					<div class="btn-group pull-right">
				 <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
			 		<i class="icon-user"></i> &nbsp;&nbsp;<?php echo $_SESSION['SESS_MEMBER_EMAIL']; ?>
			 		<span class="caret"></span>
				 </a>
				 <ul class="dropdown-menu">
			 		<li><a href="#"><i class="icon-user"></i>&nbsp;Profile</a></li>
			 		<li><a href="#"><i class="icon-cog"></i>&nbsp;Settings</a></li>
	 		 				<li class="divider"></li>
			 		<li><a href="../../execute/logout.php"><i class="icon-off"></i>&nbsp;Logout</a></li>
				 </ul>
			 	</div>
	 	</div>
			</div>
		</div>
	</div>
	<div class="m-top"></div>
	<aside class="sidebar">
		<ul class="nav nav-tabs nav-stacked">
			<li>
				<a href="index.php">
					<div>
						<div class="ico">
							<img src="../../assets/img/ico/ico-home.png">
						</div>
						<div class="title">
							Home
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			
			<li>
				<a href="courses.php">
					
					<div>
						<div class="ico">
							<img src="../../assets/img/ico/ico-notification.png">
						</div>
						<div class="title">
							Courses
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			
			<li class="active">
				<a href="profile.php">
					
					<div>
						<div class="ico">
							<img src="../../assets/img/ico/ico-user.gif">
						</div>
						<div class="title">
							Profile
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="help.html">
					<div>
						<div class="ico">
							<img src="../../assets/img/ico/ico-help.gif">
						</div>
						<div class="title">
							Help
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
	 </ul>
	</aside>
	<div class="m-sidebar-collapsed">
		<ul class="nav nav-pills">
			
		</ul>
		<div class="arrow-border">
			<div class="arrow-inner"></div>
		</div>
	</div>
	<div class="main-container">
		<div class="container-fluid">
			<section>
				<div class="page-header" style="margin-bottom:10px;">
					<h1>Profile</h1>
					<p>You can edit your preferences here.</p>
				</div>
				<?php 
					if(isset($_GET['changepass'])){
				if($_GET['changepass']=="success"){ ?>
				<div class="alert alert-success"><strong>SUCCESS:</strong><br>
				You have successfully changed your password.</div>
				<?php } else { ?>
				<div class="alert alert-error"><strong>FAILED:</strong><br>
				Wrong password changing credintials. Please try again.</div>
				<?php }
				} ?>
				
				<?php 
					if(isset($_GET['update'])){
				if($_GET['update']=="success"){ ?>
				<div class="alert alert-success"><strong>SUCCESS:</strong><br>
				Profile Changed.</div>
				<?php } else { ?>
				<div class="alert alert-error"><strong>FAILED:</strong><br>
				No changes occured.</div>
				<?php }
				} ?>
				
				<form class="form-horizontal" id="updateForm" action="execute/change_profile.php" method="post">
<fieldset>
<?php 
$qry = mysql_query("SELECT * FROM perm_members WHERE id =".$_SESSION['SESS_USER_ID']);
$row = mysql_fetch_array($qry);
?>
<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="emailid">*Email ID</label>
  <div class="controls">
    <input id="emailid" name="emailid" type="text" value="<?php echo $row['email']; ?>" class="input-xlarge required email">
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="firstname">*First Name</label>
  <div class="controls">
    <input id="firstname" name="firstname" type="text" value="<?php echo $row['firstname']; ?>" class="input-xlarge required">
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="lastname">*Last Name</label>
  <div class="controls">
    <input id="lastname" name="lastname" type="text" value="<?php echo $row['lastname']; ?>" class="input-xlarge required">
    
  </div>
</div>
<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="lastname">&nbsp;</label>
  <div class="controls">
    <a href="#" class="change-password">Change Password</a>
  </div>
</div>
<hr>
<!-- Textarea -->
<div class="control-group">
  <label class="control-label" for="bio">Bio</label>
  <div class="controls">                     
    <textarea id="bio" name="bio" class="input-xlarge"><?php echo $row['bio']; ?></textarea>
  </div>
</div>

<!-- Multiple Radios (inline) -->
<div class="control-group">
  <label class="control-label" for="gender">Gender</label>
  <div class="controls">
    <label class="radio inline" for="gender-0">
      <input type="radio" name="gender" id="gender-0" value="Male" <?php if($row['gender']=="Male") echo "checked='checked'"?>>
      Male
    </label>
    <label class="radio inline" for="gender-1">
      <input type="radio" name="gender" id="gender-1" value="Female" <?php if($row['gender']=="Female") echo "checked='checked'"?>>
      Female
    </label>
  </div>
</div>

<!-- Prepended text-->
<div class="control-group">
  <label class="control-label" for="phone">Phone</label>
  <div class="controls">
    <div class="input-prepend">
      <span class="add-on">+93</span>
      <input id="phone" name="phone" class="input-large" value="<?php echo $row['phone']; ?>" placeholder="7xxxxxxxx" type="text">
    </div>
    
  </div>
</div>

<!-- Textarea -->
<div class="control-group">
  <label class="control-label" for="address">Address</label>
  <div class="controls">                     
    <textarea id="address" name="address" class="input-xlarge"><?php echo $row['address']; ?></textarea>
  </div>
</div>
<hr>
<div class="control-group">
  <label class="control-label" for="address">&nbsp;</label>
  <div class="controls">                     
    <button type="submit" class="btn btn-primary input-xlarge"><strong>Save Changes</strong></button> 
  </div>
</div>

</fieldset>
</form>
				

</section>
</div>
</div>
<div id="change-pass-modal" class="modal hide fade">
    <div class="modal-header">
      <button class="close" data-dismiss="modal">&times;</button>
      <h3>Change Password</h3>
    </div>
            	<form class="form-horizontal" action="execute/change_password.php" method="POST">
    
        <div class="modal-body">
  <div class="control-group">
    <label class="control-label" for="inputEmail">Current Password: </label>
    <div class="controls">
      <input type="password" id="inputEmail" required placeholder="" name="cpass" class="input-large">
    </div>
  </div>
  <hr>
  
  <div class="control-group">
    <label class="control-label" for="inputPassword">New Password: </label>
    <div class="controls">
    <input type="password" name="npass" required placeholder=""/>
  </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="inputPassword">Confirm New Password: </label>
    <div class="controls">
    <input type="password" name="cnpass" required placeholder=""/>
  </div>
  </div>


    	</div>
    <div class="modal-footer">
      <button type="submit" class="btn btn-success span2 offset2">Change</button>
      <a href="#" class="btn span1" data-dismiss="modal" >Cancel</a>
    </div>
    </form> 
</div>
</body>
</html>